package com.kdx.wallet.controller;

import com.kdx.wallet.Constant;
import com.kdx.wallet.entity.User;
import com.kdx.wallet.entity.dto.CommonResponses;
import com.kdx.wallet.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 注册用户并绑定钱包
     */
    @PostMapping("/{username}")
    @ResponseBody
    public CommonResponses<String> register(@PathVariable String username) {
        User user = userService.register(username);
        if (user != null) {
            return new CommonResponses<>("success", Constant.SUCCESS_CODE, Constant.SUCCESS_MSG);
        }
        return new CommonResponses<>("failed",Constant.REGISTER_FAILED_CODE,Constant.FAILED_MSG);
    }
}
